<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>创建自定义元素</title>
</head>
<body>
  <div is="x-foo"></div>
  <div is="x-foo"></div>
  <div is="x-foo"></div>
  <script>
    class FooElement extends HTMLDivElement {
      constructor() {
        super();
        console.log('x-foo');
      }
    }
    customElements.define('x-foo', FooElement, { extends: 'div' });
    // x-foo
    // x-foo
    // x-foo
  </script>
</body>
</html>